package koscom.corebase.nam;

import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;

import javax.swing.BorderFactory;
import javax.swing.JProgressBar;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

@SuppressWarnings("serial")
public class MarketPriceCellRenderer extends JProgressBar implements TableCellRenderer {
	private Color cellColor;

	public MarketPriceCellRenderer(int min, int max, Color color, boolean reverse) {
		super(JProgressBar.HORIZONTAL, min, max);
		cellColor = color;
		if(reverse)
		{
			setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		}
		else
		{
			setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
		}
		setStringPainted(true);
		setBorder(BorderFactory.createCompoundBorder());
		setBorderPainted(false);
	}
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		setForeground(cellColor);
		if (value!=null && value instanceof String)
		{
			setValue(Integer.valueOf(value.toString().replaceAll(",","")).intValue());
			this.progressString = value.toString();
		}
			return this;
	}

}
